"""添加活动表的新列

Revision ID: add_activity_columns
Revises: 
Create Date: 2025-03-05 20:45:00

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'add_activity_columns'
down_revision = None
branch_labels = None
depends_on = None

def upgrade():
    # 添加新列
    op.add_column('activity', sa.Column('price', sa.Float(), nullable=True))
    op.add_column('activity', sa.Column('location', sa.String(length=100), nullable=True))
    op.add_column('activity', sa.Column('highlights', sa.Text(), nullable=True))
    
    # 修改现有列的约束
    op.alter_column('activity', 'title',
               existing_type=sa.String(length=128),
               type_=sa.String(length=100),
               nullable=False)
    op.alter_column('activity', 'description',
               existing_type=sa.Text(),
               nullable=False)
    op.alter_column('activity', 'date',
               existing_type=sa.DateTime(),
               nullable=False)
    op.alter_column('activity', 'image',
               existing_type=sa.String(length=128),
               type_=sa.String(length=100),
               nullable=True)

def downgrade():
    # 删除新列
    op.drop_column('activity', 'highlights')
    op.drop_column('activity', 'location')
    op.drop_column('activity', 'price')
    
    # 恢复原有列的约束
    op.alter_column('activity', 'image',
               existing_type=sa.String(length=100),
               type_=sa.String(length=128),
               nullable=True)
    op.alter_column('activity', 'date',
               existing_type=sa.DateTime(),
               nullable=True)
    op.alter_column('activity', 'description',
               existing_type=sa.Text(),
               nullable=True)
    op.alter_column('activity', 'title',
               existing_type=sa.String(length=100),
               type_=sa.String(length=128),
               nullable=True) 